﻿
using Microsoft.EntityFrameworkCore;
using Rj.PersonnelVerification.Server.DataBaseContext;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace Rj.PersonnelVerification.Server.Repositories.Impl
{
    public class HisRepository : IHisRepository
    {
        protected HisDbContext hisDbContext;

        public HisRepository(HisDbContext hisDbContext)
        {
            this.hisDbContext = hisDbContext;
        }

        public IEnumerable<T> QueryByExample<T>(Expression<Func<T, bool>> action)
            where T : class
        {
            return hisDbContext.Set<T>().Where(action).ToList();
        }

        public async Task<IEnumerable<T>> QueryByExampleAsync<T>(Expression<Func<T, bool>> action) where T : class
        {
            return await hisDbContext.Set<T>().Where(action).ToListAsync();
        }

        public async Task<T> QuerybyPrimaryKeyAsync<T>(params object[] keyValues) where T : class
        {
            return await hisDbContext.Set<T>().FindAsync(keyValues);
        }

        T IHisRepository.QuerybyPrimaryKey<T>(params object[] keyValues)
        {
            return hisDbContext.Set<T>().Find(keyValues)!;
        }
    }
}
